<template>
    <div>
        <el-dialog
            title="修改服务协议"
            :visible.sync="dialogVisible"
            width="880px"
        >
            <el-form ref="form" :model="form" label-width="120px" size="small">
                <el-form-item label="公告标题:" prop="title"
                              :rules="[{required: true, message: '请输入公告标题', trigger: 'blur'}]">
                    <el-input v-model="form.title" placeholder="请输入公告标题"></el-input>
                </el-form-item>
                <el-form-item label="公告内容:" prop="content"
                              :rules="[{required: true, message: '请输入公告内容', trigger: 'blur'}]">
                    <Editor
                        :content="form.content"
                        @bindBody="bindBody"
                        :headers="{ Authorization: 'Bearer ' + token }"
                        uploadImgUrl="/apis/base/upload/image"
                    ></Editor>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="cancel" size="small">取 消</el-button>
                <el-button type="primary" @click="onSubmit" size="small">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import {mapState} from "vuex";
import {upDateAgreement} from "@/index/api/index/setting/bg/bgServer/bgServer"
import Editor from "@/index/components/editor.vue"

export default {
    data() {
        return {
            dialogVisible: false,
            form: {
                title: "",
                content: "",
            },
        }
    },
    computed: {
        ...mapState(["token"]),
    },
    components: {Editor},
    methods: {
        cancel() {
            this.dialogVisible = false;
        },
        showDialog(e, row) {
            setTimeout(() => {this.form = row;},100)
            this.dialogVisible = !this.dialogVisible
        },
        bindBody(e) {
            this.form.content = e
        },
        onSubmit() {
            upDateAgreement(this.form, this.form.id).then(res => {
                if (res.code == 200) {
                    this.dialogVisible = false;
                    this.$message({
                        message: res.message,
                        type: "success",
                    });
                    this.$parent.getFarmList();
                    this.$refs["form"].resetFields();
                } else {
                    this.$message({
                        message: res.message,
                        type: "error",
                    });
                }
            })
        },
    }
}
</script>

<style lang="less" scoped>

.flex-container {
    display: flex;
    align-items: center; /* 垂直居中 */
    margin-top: 10px;
}
</style>
